package com.ruoyi.project.im.welcome.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.im.welcome.domain.Welcome;
import com.ruoyi.project.im.welcome.service.IWelcomeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 消息Controller
 * 
 * @author ruoyi
 * @date 2022-09-11
 */
@Controller
@RequestMapping("/Message/welcome")
public class WelcomeController extends BaseController
{
    private String prefix = "Message/welcome";

    @Autowired
    private IWelcomeService welcomeService;

    @RequiresPermissions("Message:welcome:view")
    @GetMapping()
    public String welcome()
    {
        return prefix + "/welcome";
    }

    /**
     * 查询消息列表
     */
    @RequiresPermissions("Message:welcome:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Welcome welcome)
    {
        startPage();
        List<Welcome> list = welcomeService.selectWelcomeList(welcome);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @RequiresPermissions("Message:welcome:export")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Welcome welcome)
    {
        List<Welcome> list = welcomeService.selectWelcomeList(welcome);
        ExcelUtil<Welcome> util = new ExcelUtil<Welcome>(Welcome.class);
        return util.exportExcel(list, "消息数据");
    }

    /**
     * 新增消息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息
     */
    @RequiresPermissions("Message:welcome:add")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Welcome welcome)
    {
        return toAjax(welcomeService.insertWelcome(welcome));
    }

    /**
     * 修改消息
     */
    @RequiresPermissions("Message:welcome:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") String userId, ModelMap mmap)
    {
        Welcome welcome = welcomeService.selectWelcomeByUserId(userId);
        mmap.put("welcome", welcome);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息
     */
    @RequiresPermissions("Message:welcome:edit")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Welcome welcome)
    {
        return toAjax(welcomeService.updateWelcome(welcome));
    }

    /**
     * 删除消息
     */
    @RequiresPermissions("Message:welcome:remove")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(welcomeService.deleteWelcomeByUserIds(ids));
    }
}
